#pragma once
#include<iostream>
#include<functional>
#include<memory>
#include "InetAddr.hpp"

class EpollServer;

//using func_t = std::function<void(std::shared_ptr<Connection>)>;

class Connection
{
public:
    Connection():_sockfd(-1), _events(0)
    {}
    void SetPeerInfo(const InetAddr& peer_addr)
    {
        _peer_addr = peer_addr;
    }
    void SetSockfd(int sockfd)
    {
        _sockfd = sockfd;
    }
    int Sockfd()
    {
        return _sockfd;
    }
    void SetEvents(u_int32_t events){_events = events;}
    void SerOwner(EpollServer* owner)
    {
        _owner = owner;
    }
    EpollServer* GetOwner()
    {
        return _owner;
    }
    uint32_t GetEvents(){return _events;}
    //回调方法
    virtual void _Recver()=0;
    virtual void _Sender()=0;
    virtual void _Excepter()=0;
    ~Connection()
    {}
protected:
    int _sockfd;
    std::string _inbuffer;
    std::string _outbuffer;
    InetAddr _peer_addr;    //对应客户端


    //指针
    EpollServer* _owner;
    //我关心的事件
    u_int32_t _events; //该connention关心的事件
};

// class Facotry
// {
// public:
//     static std::shared_ptr<Connection> BuildConnection(int fd, uint32_t events, func_t r, func_t s, func_t e)
//     {
//         auto conn = std::make_shared<Connection>(fd);
//         conn->SetEvents(events);
//         conn->InitCB(r,s,e);
//         return conn;
//     }
// };